home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!bbn.com!rsalz
- From: rsalz@uunet.uu.net (Rich Salz)
- Newsgroups: comp.sources.unix
- Subject: v18i074: MIT Athena delete/undelete programs, Part02/06
- Message-ID: <1634@fig.bbn.com>
- Date: 29 Mar 89 04:31:26 GMT
- Lines: 815
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: Jonathan I. Kamens <jik@PIT-MANAGER.MIT.EDU>
- Posting-number: Volume 18, Issue 74
- Archive-name: undel/part02
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 2 (of 6)."
- # Contents: Makefile col.c man1/delete.1 util.c
- # Wrapped by jik@pit-manager on Mon Mar 27 12:16:48 1989
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(4426 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# Copyright 1988 Massachusetts Institute of Technology.
- X#
- X# For copying and distribution information, see the file
- X# "mit-copyright.h".
- X#
- X# $Source: /mit/jik/src/delete/RCS/Makefile,v $
- X# $Author: jik $
- X# $Header: Makefile,v 1.8 89/03/27 12:03:33 jik Exp $
- X#
- X
- XDESTDIR =
- XTARGETS = delete undelete expunge purge lsdel
- XINSTALLDIR = /bin/athena
- XCC = cc
- XCFLAGS = -O
- XSRCS = delete.c undelete.c directories.c pattern.c util.c expunge.c \
- X lsdel.c col.c
- X
- Xall: $(TARGETS)
- X
- Xinstall:
- X for i in $(TARGETS) ;\
- X do \
- X install -c -s $$i $(DESTDIR)$(INSTALLDIR) ; \
- X install -c man1/$$i.1 $(DESTDIR)/usr/man/man1 ; \
- X done
- X
- Xdelete: delete.o util.o
- X cc $(CFLAGS) -o delete delete.o util.o
- X
- Xsaber_delete:
- X #alias s step
- X #alias n next
- X #load delete.c util.c
- X
- Xundelete: undelete.o directories.o util.o pattern.o
- X cc $(CFLAGS) -o undelete undelete.o directories.o util.o pattern.o
- X
- Xsaber_undelete:
- X #alias s step
- X #alias n next
- X #load undelete.c directories.c util.c pattern.c
- X
- Xexpunge: expunge.o directories.o pattern.o util.o col.o
- X cc $(CFLAGS) -o expunge expunge.o directories.o pattern.o \
- X util.o col.o
- X
- X
- Xsaber_expunge:
- X #alias s step
- X #alias n next
- X #load expunge.c directories.c pattern.c util.c col.c
- X
- Xpurge: expunge
- X ln -s expunge purge
- X
- Xlsdel: lsdel.o util.o directories.o pattern.o col.o
- X cc $(CFLAGS) -o lsdel lsdel.o util.o directories.o pattern.o col.o
- X
- Xsaber_lsdel:
- X #alias s step
- X #alias n next
- X #load lsdel.c util.c directories.c pattern.c col.c
- X
- Xclean:
- X -rm -f *~ *.bak *.o delete undelete lsdel expunge purge
- X
- Xdepend: delete.c undelete.c
- X /usr/athena/makedepend -v $(CFLAGS) -s'# DO NOT DELETE' $(SRCS)
- X
- X# DO NOT DELETE THIS LINE -- makedepend depends on it
- X
- Xdelete.o: /usr/include/sys/types.h /usr/include/stdio.h
- Xdelete.o: /usr/include/sys/stat.h /usr/include/sys/dir.h
- Xdelete.o: /usr/include/strings.h /usr/include/sys/param.h
- X# /usr/include/sys/param.h includes:
- X# machine/machparam.h
- X# signal.h
- X# sys/types.h
- Xdelete.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
- Xdelete.o: /usr/include/sys/file.h util.h
- X# util.h includes:
- X# mit-copyright.h
- Xdelete.o: mit-copyright.h delete.h
- X# delete.h includes:
- X# mit-copyright.h
- Xundelete.o: /usr/include/stdio.h /usr/include/sys/types.h
- Xundelete.o: /usr/include/sys/dir.h /usr/include/sys/param.h
- Xundelete.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
- Xundelete.o: /usr/include/strings.h /usr/include/sys/stat.h directories.h
- X# directories.h includes:
- X# mit-copyright.h
- Xundelete.o: mit-copyright.h pattern.h
- X# pattern.h includes:
- X# mit-copyright.h
- Xundelete.o: util.h undelete.h
- X# undelete.h includes:
- X# mit-copyright.h
- Xdirectories.o: /usr/include/sys/types.h /usr/include/sys/stat.h
- Xdirectories.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
- Xdirectories.o: /usr/include/sys/signal.h /usr/include/sys/dir.h
- Xdirectories.o: /usr/include/strings.h directories.h mit-copyright.h util.h
- Xpattern.o: /usr/include/stdio.h /usr/include/sys/types.h
- Xpattern.o: /usr/include/sys/dir.h /usr/include/sys/param.h
- Xpattern.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
- Xpattern.o: /usr/include/strings.h /usr/include/sys/stat.h directories.h
- Xpattern.o: mit-copyright.h pattern.h util.h undelete.h
- Xutil.o: /usr/include/stdio.h /usr/include/sys/param.h
- Xutil.o: /usr/include/machine/machparam.h /usr/include/sys/signal.h
- Xutil.o: /usr/include/sys/types.h /usr/include/sys/stat.h
- Xutil.o: /usr/include/sys/dir.h /usr/include/strings.h /usr/include/pwd.h
- Xutil.o: directories.h mit-copyright.h util.h
- Xexpunge.o: /usr/include/stdio.h /usr/include/sys/types.h
- Xexpunge.o: /usr/include/sys/time.h
- X# /usr/include/sys/time.h includes:
- X# time.h
- Xexpunge.o: /usr/include/sys/time.h /usr/include/sys/dir.h
- Xexpunge.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
- Xexpunge.o: /usr/include/sys/signal.h /usr/include/strings.h
- Xexpunge.o: /usr/include/sys/stat.h col.h
- X# col.h includes:
- X# mit-copyright.h
- Xexpunge.o: mit-copyright.h directories.h util.h pattern.h expunge.h
- X# expunge.h includes:
- X# mit-copyright.h
- Xlsdel.o: /usr/include/stdio.h /usr/include/sys/types.h /usr/include/sys/dir.h
- Xlsdel.o: /usr/include/sys/param.h /usr/include/machine/machparam.h
- Xlsdel.o: /usr/include/sys/signal.h /usr/include/sys/stat.h
- Xlsdel.o: /usr/include/strings.h col.h mit-copyright.h util.h directories.h
- Xlsdel.o: pattern.h lsdel.h
- X# lsdel.h includes:
- X# mit-copyright.h
- Xcol.o: /usr/include/stdio.h /usr/include/strings.h col.h mit-copyright.h
- END_OF_FILE
- if test 4426 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'col.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'col.c'\"
- else
- echo shar: Extracting \"'col.c'\" \(5298 characters\)
- sed "s/^X//" >'col.c' <<'END_OF_FILE'
- X/*
- X * $Source: /mit/jik/src/delete/RCS/col.c,v $
- X * $Author: jik $
- X *
- X * This program is part of a package including delete, undelete,
- X * lsdel, expunge and purge. The software suite is meant as a
- X * replacement for rm which allows for file recovery.
- X *
- X * Copyright (c) 1989 by the Massachusetts Institute of Technology.
- X * For copying and distribution information, see the file "mit-copyright.h."
- X */
- X
- X#if (!defined(lint) && !defined(SABER))
- X static char rcsid_col_c[] = "$Header: col.c,v 1.2 89/03/27 12:05:12 jik Exp $";
- X#endif
- X
- X/*
- X * Note that this function has a lot of options I'm not really using
- X * because I took it out of other code that needed a lot more
- X * versatility.
- X */
- X
- X#include <stdio.h>
- X#include <strings.h>
- X#include "col.h"
- X#include "mit-copyright.h"
- X
- X
- Xstatic int calc_string_width();
- Xstatic void trim_strings();
- Xextern char *malloc();
- Xextern char *whoami;
- X
- Xint column_array(strings, num_to_print, screen_width, column_width,
- X number_of_columns, margin, spread_flag,
- X number_flag, var_col_flag, outfile)
- Xchar **strings;
- XFILE *outfile;
- X{
- X char buf[BUFSIZ];
- X int updown, leftright, height;
- X int string_width;
- X int numwidth;
- X
- X
- X numwidth = num_width(num_to_print);
- X if (! var_col_flag) {
- X string_width = calc_string_width(column_width, margin, number_flag,
- X num_to_print);
- X if (string_width < 0) {
- X fprintf(stderr,
- X "%s: do_wait: your columns aren't wide enough!\n",
- X whoami);
- X return(1);
- X }
- X trim_strings(strings, num_to_print, string_width);
- X } else if (calc_widths(strings, &screen_width, &column_width,
- X &number_of_columns, num_to_print, &margin,
- X spread_flag, number_flag))
- X return(1);
- X
- X height = num_to_print / number_of_columns;
- X if (num_to_print % number_of_columns)
- X height++;
- X
- X if (number_flag) for (updown = 0; updown < height; updown++) {
- X for (leftright = updown; leftright < num_to_print;
- X leftright += height) {
- X (void) sprintf(buf, "%*d. %s", numwidth, leftright+1,
- X strings[leftright]);
- X fprintf(outfile, "%*s", -column_width, buf);
- X }
- X fprintf(outfile, "\n");
- X } else for (updown = 0; updown < height; updown++) {
- X for (leftright = updown; leftright < num_to_print;
- X leftright += height) {
- X (void) sprintf(buf, "%s", strings[leftright]);
- X fprintf(outfile, "%*s", -column_width, buf);
- X }
- X fprintf(outfile, "\n");
- X }
- X
- X return(0);
- X}
- X
- Xstatic int calc_string_width(column_width, margin, number_flag, max_number)
- X{
- X int string_width;
- X
- X string_width = column_width - margin;
- X if (number_flag)
- X string_width = string_width - num_width(max_number) - strlen(". ");
- X return(string_width);
- X}
- X
- X
- Xstatic void trim_strings(strings, number, width)
- Xchar **strings;
- X{
- X int loop;
- X
- X for (loop = 0; loop < number; loop++)
- X if (strlen(strings[loop]) > width)
- X strings[loop][width] = '\0';
- X}
- X
- X
- Xstatic int calc_widths(strings, screen_width, column_width, number_of_columns,
- X num_to_print, margin, spread_flag, number_flag)
- Xint *screen_width, *column_width, *number_of_columns, *margin;
- Xchar **strings;
- X{
- X int loop;
- X int maxlen, templen;
- X int spread;
- X
- X#ifdef DEBUG
- X printf("calc_widths starting with screen_width %d column_width %d number_of_columns %d margin %d num_to_print %d spread_flag %d number_flag %d\n", *screen_width, *column_width, *number_of_columns, *margin, num_to_print, spread_flag, number_flag);
- X#endif
- X maxlen = templen = 0;
- X for (loop = 0; loop < num_to_print; loop++)
- X if (maxlen < (templen = strlen(strings[loop])))
- X maxlen = templen;
- X#ifdef DEBUG
- X printf("calc_widths maxlen %d\n", maxlen);
- X#endif
- X *column_width = maxlen;
- X
- X if (number_flag)
- X *column_width = *column_width + num_width(num_to_print) +
- X strlen(". ");
- X
- X if (! spread_flag) {
- X *column_width += *margin;
- X if (! *number_of_columns) {
- X *number_of_columns = *screen_width / *column_width;
- X if (! *number_of_columns) {
- X (*number_of_columns)++;
- X *column_width -= *margin;
- X *margin = 0;
- X *screen_width = *column_width;
- X }
- X }
- X else
- X *screen_width = *number_of_columns * *column_width;
- X } else {
- X if (! *number_of_columns) {
- X *number_of_columns = *screen_width / (*column_width + *margin);
- X if (! *number_of_columns) {
- X (*number_of_columns)++;
- X *screen_width = *column_width;
- X *margin = 0;
- X }
- X spread = (*screen_width - *number_of_columns * *column_width)
- X / *number_of_columns;
- X *column_width += spread;
- X }
- X else {
- X if (*number_of_columns * (*column_width + *margin) >
- X *screen_width) {
- X *column_width += *margin;
- X *screen_width = *column_width;
- X } else {
- X spread = (*screen_width - (*number_of_columns *
- X *column_width)) /
- X *number_of_columns;
- X *column_width += spread;
- X }
- X }
- X }
- X#ifdef DEBUG
- X printf("calc_widths returning screen_width %d column_width %d number_of_columns %d margin %d\n", *screen_width, *column_width, *number_of_columns, *margin);
- X#endif
- X return(0);
- X}
- X
- X
- X
- X
- Xstatic int num_width(number)
- X{
- X char buf[BUFSIZ];
- X
- X return(strlen(sprintf(buf, "%d", number)));
- X}
- END_OF_FILE
- if test 5298 -ne `wc -c <'col.c'`; then
- echo shar: \"'col.c'\" unpacked with wrong size!
- fi
- # end of 'col.c'
- fi
- if test -f 'man1/delete.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'man1/delete.1'\"
- else
- echo shar: Extracting \"'man1/delete.1'\" \(3945 characters\)
- sed "s/^X//" >'man1/delete.1' <<'END_OF_FILE'
- X.\" $Source: /mit/jik/src/delete/man1/RCS/delete.1,v $
- X.\" $Author: jik $
- X.\" $Header: delete.1,v 1.4 89/03/27 11:32:54 jik Exp $
- X.\"
- X.\" Copyright 1989 by the Massachusetts Institute of Technology. All
- X.\" rights reserved. The file /usr/include/mit-copyright.h specifies
- X.\" the terms and conditions for redistribution.
- X.\"
- X.\"
- X.TH DELETE 1 "January 26, 1988" "MIT Project Athena"
- X.ds ]W MIT Project Athena
- X.SH NAME
- Xdelete \- a recoverable file-deletion utility
- X.SH SYNOPSIS
- X.B delete
- X[
- X.B \-r
- X] [
- X.B \-i
- X] [
- X.B \-f
- X] [
- X.B \-n
- X] [
- X.B \-v
- X] [
- X.B \-F
- X] [
- X.B \-D
- X] [
- X.B \-\|\-
- X] filename ...
- X.PP
- X.SH DESCRIPTION
- X.I Delete
- Xmarks files and directories for later permanent removal (by renaming
- Xthem with a prefix of \fI.#\fR). Files accidentally marked for deletion
- Xcan be recovered using
- X.I undelete(1).
- XMarked files are periodically
- Xremoved automatically by the system; they can also be removed on demand
- X(see \fIpurge\fR(1) and \fIexpunge\fR(1) for details).
- XUsers can list files which have been marked for
- Xremoval but have not yet been removed using \fIlsdel\fR(1).
- X.PP
- XIf the user does not have write permission to a file, its permissions
- Xare printed and the user is asked whether the file should be removed.
- XIf the first character of the response line is \fIy\fR the file is
- Xremoved, otherwise it remains.
- X.PP
- XUsers wishing to retain the user interface of \fIrm\fR(1)
- Xand \fIrmdir\fR(1)
- Xwhile still being able to recover accidentally removed files can do so
- Xby aliasing
- X.I rm
- Xto
- X.I delete \-F
- Xand
- X.I rmdir
- Xto
- X.I delete \-D
- X(see below).
- X.SH OPTIONS
- X.I Delete
- Xaccepts the following command-line options:
- X.TP
- X.B \-r
- XIf a designated filename is a non-empty directory,
- X.I delete
- Xwill signal an error unless the
- X.B \-r
- Xoption is specified. In that case,
- X.I delete
- Xrecursively deletes the directory's entire contents and the directory
- Xitself. If the
- X.B \-F
- Xoption is specified (see below),
- X.I delete
- Xwill signal an error even if the directory is empty.
- X.TP
- X.B \-i
- XCauses
- X.I delete
- Xto ask whether to delete each file, and, in recursive
- Xmode, whether to examine each directory.
- X.TP
- X.B \-f
- XPrevents
- X.I delete
- Xfrom asking any questions and from reporting any errors.
- X.TP
- X.B \-n
- XNo file removals are performed. Instead,
- X.I delete
- Xprints to the standard output the files that it would remove were the
- X.B \-n
- Xoption not specified.
- X.TP
- X.B \-v
- XCauses
- X.I delete
- Xto report each file as it is deleted.
- X.TP
- X.B \-F
- XCauses
- X.I delete
- Xto emulate
- X.I rm
- Xby preventing it from removing even empty directories when the
- X.B \-r
- Xoption is not specified.
- X.TP
- X.B \-D
- XCauses
- X.I delete
- Xto emulate
- X.I rmdir
- Xby preventing it from removing anything but empty directories.
- X.TP
- X.B \-\|\-
- XTwo dashes indicate that all the arguments following it are to be treated as
- Xfile names, even if they start with a dash.
- X.SH "SEE ALSO"
- Xundelete(1), purge(1), expunge(1), lsdel(1), rm(1), rmdir(1)
- X.SH AUTHOR
- XJonathan I. Kamens (MIT-Project Athena)
- X.SH COPYRIGHT
- XCopyright (c) 1989 by the Massachusetts Institute of Technology.
- X.PP
- XAll rights reserved.
- X.PP
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the name of the Massachusetts
- XInstitute of Technology (M.I.T.) not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X.PP
- XM.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- XM.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- XSOFTWARE.
- X
- X
- END_OF_FILE
- if test 3945 -ne `wc -c <'man1/delete.1'`; then
- echo shar: \"'man1/delete.1'\" unpacked with wrong size!
- fi
- # end of 'man1/delete.1'
- fi
- if test -f 'util.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'util.c'\"
- else
- echo shar: Extracting \"'util.c'\" \(4579 characters\)
- sed "s/^X//" >'util.c' <<'END_OF_FILE'
- X/*
- X * $Source: /mit/jik/src/delete/RCS/util.c,v $
- X * $Author: jik $
- X *
- X * This program is a replacement for rm. Instead of actually deleting
- X * files, it marks them for deletion by prefixing them with a ".#"
- X * prefix.
- X *
- X * Copyright (c) 1989 by the Massachusetts Institute of Technology.
- X * For copying and distribution information, see the file "mit-copyright.h."
- X */
- X
- X#if (!defined(lint) && !defined(SABER))
- X static char rcsid_util_c[] = "$Header: util.c,v 1.7 89/03/27 12:08:34 jik Exp $";
- X#endif
- X
- X#include <stdio.h>
- X#include <sys/param.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <sys/dir.h>
- X#include <strings.h>
- X#include <pwd.h>
- X#include "directories.h"
- X#include "util.h"
- X#include "mit-copyright.h"
- X
- Xchar *getenv();
- X
- X
- Xchar *convert_to_user_name(real_name, user_name)
- Xchar real_name[];
- Xchar user_name[]; /* RETURN */
- X{
- X char *ptr, *q;
- X
- X strcpy(user_name, real_name);
- X while (ptr = strrindex(user_name, ".#")) {
- X for (q = ptr; *(q + 2); q++)
- X *q = *(q + 2);
- X *q = '\0';
- X }
- X return (user_name);
- X}
- X
- X
- X
- X
- X
- Xchar *strindex(str, sub_str)
- Xchar *str, *sub_str;
- X{
- X char *ptr = str;
- X while (ptr = index(ptr, *sub_str)) {
- X if (! strncmp(ptr, sub_str, strlen(sub_str)))
- X return(ptr);
- X ptr++;
- X }
- X return ((char *) NULL);
- X}
- X
- X
- X
- Xchar *strrindex(str, sub_str)
- Xchar *str, *sub_str;
- X{
- X char *ptr;
- X
- X if (strlen(str))
- X ptr = &str[strlen(str) - 1];
- X else
- X return((char *) NULL);
- X while ((*ptr != *sub_str) && (ptr != str)) ptr--;
- X while (ptr != str) {
- X if (! strncmp(ptr, sub_str, strlen(sub_str)))
- X return(ptr);
- X ptr--;
- X while ((*ptr != *sub_str) && (ptr != str)) ptr--;
- X }
- X if (! strncmp(ptr, sub_str, strlen(sub_str)))
- X return(str);
- X else
- X return ((char *) NULL);
- X}
- X
- X
- Xis_dotfile(filename)
- Xchar *filename;
- X{
- X return (! (strcmp(filename, ".") && strcmp(filename, "..")));
- X}
- X
- X
- X
- Xint is_deleted(filename)
- Xchar *filename;
- X{
- X return(! strncmp(filename, ".#", 2));
- X}
- X
- X
- X
- X
- X/*
- X * NOTE: Append uses a static array, so its return value must be
- X * copied immediately.
- X */
- Xchar *append(filepath, filename)
- Xchar *filepath, *filename;
- X{
- X static char buf[MAXPATHLEN];
- X
- X strcpy(buf, filepath);
- X if ((! *filename) || (! *filepath)) {
- X strcpy(buf, filename);
- X return(buf);
- X }
- X if (buf[strlen(buf) - 1] == '/')
- X buf[strlen(buf) - 1] = '\0';
- X if (strlen(buf) + strlen(filename) + 2 > MAXPATHLEN) {
- X *buf = '\0';
- X return(buf);
- X }
- X strcat(buf, "/");
- X strcat(buf, filename);
- X return(buf);
- X}
- X
- X
- X
- X
- Xyes() {
- X char buf[BUFSIZ];
- X char *val;
- X
- X val = fgets(buf, BUFSIZ, stdin);
- X if (! val) {
- X printf("\n");
- X exit(1);
- X }
- X if (! index(buf, '\n')) do
- X fgets(buf + 1, BUFSIZ - 1, stdin);
- X while (! index(buf + 1, '\n'));
- X return(*buf == 'y');
- X}
- X
- X
- X
- X
- Xchar *lastpart(filename)
- Xchar *filename;
- X{
- X char *part;
- X
- X part = rindex(filename, '/');
- X
- X if (! part)
- X part = filename;
- X else if (part == filename)
- X part++;
- X else if (part - filename + 1 == strlen(filename)) {
- X part = rindex(--part, '/');
- X if (! part)
- X part = filename;
- X else
- X part++;
- X }
- X else
- X part++;
- X
- X return(part);
- X}
- X
- X
- X
- X
- Xchar *firstpart(filename, rest)
- Xchar *filename;
- Xchar *rest; /* RETURN */
- X{
- X char *part;
- X static char buf[MAXPATHLEN];
- X
- X strcpy(buf, filename);
- X part = index(buf, '/');
- X if (! part) {
- X *rest = '\0';
- X return(buf);
- X }
- X strcpy(rest, part + 1);
- X *part = '\0';
- X return(buf);
- X}
- X
- X
- X
- X
- Xchar *reg_firstpart(filename, rest)
- Xchar *filename;
- Xchar *rest; /* RETURN */
- X{
- X static char first[MAXNAMLEN];
- X
- X sprintf(first, "^%s$", firstpart(filename, rest));
- X return(first);
- X}
- X
- X
- X
- X
- X
- X
- Xget_home(buf)
- Xchar *buf;
- X{
- X char *user;
- X struct passwd *psw;
- X
- X strcpy(buf, getenv("HOME"));
- X
- X if (*buf)
- X return(0);
- X
- X user = getenv("USER");
- X psw = getpwnam(user);
- X
- X if (psw) {
- X strcpy(buf, psw->pw_dir);
- X return(0);
- X }
- X
- X psw = getpwuid(getuid());
- X
- X if (psw) {
- X strcpy(buf, psw->pw_dir);
- X return(0);
- X }
- X return(1);
- X}
- X
- X
- X
- X
- Xtimed_out(file_ent, current_time, min_days)
- Xfilerec *file_ent;
- Xint current_time, min_days;
- X{
- X if ((current_time - file_ent->specs.st_mtime) / 86400 >= min_days)
- X return(1);
- X else
- X return(0);
- X}
- X
- X
- X
- Xint directory_exists(dirname)
- Xchar *dirname;
- X{
- X struct stat stat_buf;
- X
- X if (stat(dirname, &stat_buf))
- X return(0);
- X else if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
- X return(1);
- X else
- X return(0);
- X}
- X
- X
- END_OF_FILE
- if test 4579 -ne `wc -c <'util.c'`; then
- echo shar: \"'util.c'\" unpacked with wrong size!
- fi
- # end of 'util.c'
- fi
- echo shar: End of archive 2 \(of 6\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 3 4 5 6 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 6 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
- --
- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
-
-
-